//
//  RatingView.m
//  ratingView
//
//  Created by Mac on 15/7/29.
//  Copyright (c) 2015年 BV-3G. All rights reserved.
//

#import "RatingView.h"

@implementation RatingView
{

    UIView *_grayView;
    UIView *_yellowView;

}

- (void)awakeFromNib {

    [super awakeFromNib];
    
    self.backgroundColor = [UIColor clearColor];
    
    [self creatStarView];

}

- (void)creatStarView {

    UIImage *gray = [UIImage imageNamed:@"gray"];
    UIImage *yellow = [UIImage imageNamed:@"yellow"];
    
    //1.获取星星视图的初始的宽高
    CGFloat width = gray.size.width *5;
    CGFloat height = gray.size.height;
    
    //2.初始化星星视图
    _grayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
    [_grayView setBackgroundColor:[UIColor colorWithPatternImage:gray]];
    [self addSubview:_grayView];
    
    _yellowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
    [_yellowView setBackgroundColor:[UIColor colorWithPatternImage:yellow]];
    [self addSubview:_yellowView];
    
    //3.放大星星视图与self等高等宽
    CGFloat scale = self.frame.size.width/width;
    
    _grayView.transform = CGAffineTransformMakeScale(scale, scale);
    _yellowView.transform = CGAffineTransformMakeScale(scale, scale);
    
    //4.重置星星视图的坐标
    _grayView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    _yellowView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    
}

- (void)setRating:(float)rating {

    _rating = rating;

    
    _yellowView.frame = CGRectMake(0, 0, self.frame.size.width *rating/10, self.frame.size.height);
    
}

@end
